<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of RegisterFormUserclass
 *
 * @author destiya
 */
class RegisterFormUser extends BaseuserForm {
    public function configure() {
        $this->useFields(array('nama', 'email'));

        unset($this['id']);


        /*
         *
         * Widget Settings
         *
         */
        $this->widgetSchema['id_profesi'] = new sfWidgetFormChoice(array(
            'choices'=>Doctrine_Core::getTable('setProfesi')->getProfesiList(),
            'expanded'=>false,
            'multiple'=>false,
            'label'=>'Profesi'
        ));

        $years = range(1930, date('Y'));
        $this->widgetSchema['tanggal_lahir'] = new sfWidgetFormI18nDate(array(
            'culture'=>'id',
            'format'=>'%day% - %month% - %year%',
            'years'=>array_combine($years, $years)
        ));

        $this->widgetSchema['id_propinsi'] = new sfWidgetFormChoice(array(
            'choices'=>Doctrine_Core::getTable('setPropinsi')->getPropinsiList(),
            'expanded'=>false,
            'multiple'=>false,
            'label'=>'Propinsi'
        ));

        $this->widgetSchema['id_kota'] = new sfWidgetFormChoice(array(
            'choices'=>Doctrine_Core::getTable('setKota')->getKotaList(),
            'expanded'=>false,
            'multiple'=>false,
            'label'=>'Kota'
        ));

        $this->widgetSchema['id_sekolah'] = new sfWidgetFormChoice(array(
            'choices'=>Doctrine_Core::getTable('sekolah')->getSekolahList(),
            'expanded'=>false,
            'multiple'=>false,
            'label'=>'Sekolah'
        ));


        /*
         *
         * Validator Settings
         *
         */
        $this->validatorSchema['nama'] = new sfValidatorAnd(array(
            $this->validatorSchema['nama'], new sfValidatorString(array(
                'trim'=>true, 'min_length'=>4), array(
                    'min_length'=>'Nama minimal 4 karakter'
                ))
        ), array(), array('required'=>'Nama harus diisi'));

        $this->validatorSchema['email'] = new sfValidatorAnd(array(
            $this->validatorSchema['email'], new sfValidatorEmail(array(), 
                    array('invalid'=>'Alamat email yang Anda masukkan tidak valid atau telah digunakan oleh user lain'))
        ), array(), array('required'=>'Email harus diisi'));

        $this->validatorSchema['id_profesi'] = new sfValidatorChoice(array(
            'choices'=>array_keys(Doctrine_Core::getTable('setProfesi')->getProfesiList())
        ));

        $this->validatorSchema['tanggal_lahir'] = new sfValidatorAnd(array(
            new sfValidatorDate(array('required'=>false))
        ));

        $this->validatorSchema['id_propinsi'] = new sfValidatorAnd(array(
            new sfValidatorChoice(array(
                'choices'=>array_keys(Doctrine_Core::getTable('setPropinsi')->getPropinsiList())
            ))
        ));

        $this->validatorSchema['id_kota'] = new sfValidatorAnd(array(
            new sfValidatorChoice(array(
                'choices'=>array_keys(Doctrine_Core::getTable('setKota')->getKotaList())
            ))
        ));

        $this->validatorSchema['id_sekolah'] = new sfValidatorAnd(array(
            new sfValidatorChoice(array(
                'choices'=>array_keys(Doctrine_Core::getTable('sekolah')->getSekolahList())
            ))
        ));
        

        
    }

     public function saveEmbeddedForms($conn = null, $form = null) {
         if(is_null($conn)) {
             $conn = $this->getConnection();
         }

         if(is_null($form)) {
             $form = $this->getEmbeddedForm('login');
         }

         if($form instanceof sfFormDoctrine) {
             $method_name = 'setAppUserId';
             $form->getObject()->$method_name($this->getObject()->getId());
             $form->getObject()->save($conn);
             $form->saveEmbeddedForms($conn);
         } else {

         }
     }
}
?>
